package com.project.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 * @Author(王思翰)
 * @Description(类的描述)
 * @Date(创建时间) 2021/7/19 13:44
 */
public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求编码集
        req.setCharacterEncoding("utf-8");
        //设置响应信息的MIME类型和编码集
        resp.setContentType("text/html;charset=utf-8");

        String info="";
        info+="用户名:"+req.getParameter("userName")+"<br>";
        info+="性别:"+req.getParameter("sex")+"<br>";
        info+="学历:"+req.getParameter("edu")+"<br>";

        String[] likeArray=req.getParameterValues("like");
        info+="爱好:"+ Arrays.toString(likeArray);

        //得到打印流，可以向客户端输入文本数据
        PrintWriter out=resp.getWriter();
        out.println(info);
    }
}
